<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 表格 -->
    <template>
      <el-table :data="powerList" border style="width:500px">
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column prop="authName" label="权限" width="180">
        </el-table-column>
        <el-table-column prop="path" label="路径" width="180">
        </el-table-column>
        <!-- 用scope获取level的值，然后再添加过滤器 -->
        <el-table-column prop="level" label="层级" width="89">
          <template slot-scope="scope">
            <span>{{scope.row.level | getLevelMsg}}</span>
          </template>
        </el-table-column>
      </el-table>
    </template>
  </div>
</template>

<script>
import { getPowerList } from '@/api/index.js'
export default {
  data () {
    return {
      powerList: []
    }
  },
  mounted () {
    getPowerList('list').then((res) => {
      console.log(res)
      this.powerList = res.data
    })
  },
  // 添加局部过滤器
  filters: {
    getLevelMsg (level) {
      if (level === '0') {
        level = '一级'
      } else if (level === '1') {
        level = '二级'
      } else if (level === '2') {
        level = '三级'
      } else {
        level = 'aa'
      }
      return level
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
